package com.hdsx.validator;

import java.io.IOException;
import java.math.BigDecimal;
import java.net.UnknownHostException;

import javax.servlet.ServletContextEvent;

import com.esri.arcgis.geometry.IGeometry;
import com.esri.arcgis.geometry.IPoint;
import com.esri.arcgis.geometry.Point;
import com.esri.arcgis.interop.AutomationException;
import com.esri.arcgis.system.AoInitialize;
import com.esri.arcgis.system.EngineInitializer;
import com.esri.arcgis.system.esriLicenseProductCode;
import com.esri.arcgis.system.esriLicenseStatus;
import com.hdsx.validator.validate.annotation.Express;
import com.hdsx.validator.validate.annotation.JTS;
import com.hdsx.validator.validate.annotation.JTS2;
import com.hdsx.validator.validate.annotation.OGNL;
import com.hdsx.validator.validate.annotation.Regex;
import com.hdsx.validator.validate.annotation.Spatial;
import com.hdsx.validator.validate.handler.DefaultValidator;
import com.hdsx.validator.validate.handler.IValidator;
import com.hdsx.validator.validate.log.HDLog;
import com.hdsx.validator.validate.log.ILog;

public class GisQl {

	/**
	 * @description 桥梁代码
	 */
	@Regex(express =Express.CODE_L,message="路线代码 + 行政区划 + 桥梁代码（L+四位数字）总长度不低于11位 例如：G105360722L0150")
    private String qldm;
	/**
	 * @description 桥梁名称
	 */
    private String qlmc;
   
	/**
	 * @description 桥梁跨径分类代码
	 */
    private int qlkjfldm;
	/**
	 * @description 桥梁中心桩号
	 */
    //@Regex(express =Express.NUM_3P)
    private double qlzxzh;
	/**
	 * @description 偏移桩号
	 */
    private double pyzh;
	/**
	 * @description 设计荷载等级代码
	 */
    private int sjhzdjdm;
	/**
	 * @description 桥梁技术状况评定代码
	 */
   // @OGNL(expression="(qlkjfldm==1 && (qlqc>=1000||qlqc<=20000))||(qlkjfldm==2 && (qlqc>=100||qlqc<=1000))||(qlkjfldm==3 && (qlqc>=30||qlqc<=100))||(qlkjfldm==4 && (qlqc>=8||qlqc<=30))",message="桥梁跨径分类为1时10>qlqc>4000" )
    private int qljszkpddm;
	/**
	 * @description 桥梁全长
	 */
   // @OGNL(expression="qlqc>=5&&qlqc<=20000",message="桥梁长度应该在5-20000米之间")
    private double qlqc;
	/**
	 * @description 桥面全宽
	 */
   // @OGNL(expression="qmqk>=5&&qmqk<=300",message="桥面全宽应该在2-300米范围内")
    private double qmqk;
	/**
	 * @description 桥面净宽
	 */
   // @OGNL(expression="qmjk>=2&&qmjk<=qmqk",message="桥面净宽应该大于2米,小于等于桥面全宽")
    private double qmjk;
	/**
	 * @description 按使用年限分类代码
	 */
    private int asynxfldm;
    
    private Integer sxxfx;

	public Integer getSxxfx() {
		return this.sxxfx;
	}
	public void setSxxfx(int sxxfx) {
		if(sxxfx!=99)this.sxxfx = sxxfx;else this.sxxfx = null;
	}
	
	public String getQldm() {
		return qldm;
	}
	public void setQldm(String qldm) {
		/*if(!qldm.equals(""))
		{
			setXzqhbm(qldm.substring(qldm.length()-11, qldm.length()-5));
		}*/
		this.qldm = qldm;
	}
	public String getQlmc() {
		return qlmc;
	}
	public void setQlmc(String qlmc) {
		this.qlmc = qlmc;
	}
	public int getQlkjfldm() {
		return qlkjfldm;
	}
	public void setQlkjfldm(int qlkjfldm) {
		this.qlkjfldm = qlkjfldm;
	}
	public double getQlzxzh() {
		return qlzxzh;
	}
	public void setQlzxzh(double qlzxzh) {
		BigDecimal b = new BigDecimal(qlzxzh);
	    double f1  = b.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
		this.qlzxzh = f1;
	}
	public double getPyzh() {
		return pyzh;
	}
	public void setPyzh(double pyzh) {
		this.pyzh = pyzh;
	}
	public int getSjhzdjdm() {
		return sjhzdjdm;
	}
	public void setSjhzdjdm(int sjhzdjdm) {
		this.sjhzdjdm = sjhzdjdm;
	}
	public int getQljszkpddm() {
		return qljszkpddm;
	}
	public void setQljszkpddm(int qljszkpddm) {
		this.qljszkpddm = qljszkpddm;
	}
	public double getQlqc() {
		return qlqc;
	}
	public void setQlqc(double qlqc) {
		this.qlqc = qlqc;
	}
	public double getQmqk() {
		return qmqk;
	}
	public void setQmqk(double qmqk) {
		this.qmqk = qmqk;
	}
	public double getQmjk() {
		return qmjk;
	}
	public void setQmjk(double qmjk) {
		this.qmjk = qmjk;
	}
	public int getAsynxfldm() {
		return asynxfldm;
	}
	public void setAsynxfldm(int asynxfldm) {
		this.asynxfldm = asynxfldm;
	}
	private String kj;//跨径代码
	
	public String getKj() {
		return kj;
	}
	public void setKj(String kj) {
		this.kj = kj;
	}
	private String nx;//使用年限分类
	
	public String getNx() {
		return nx;
	}
	public void setNx(String nx) {
		this.nx = nx;
	}
	private String pd;//评定等级分类
	
	public String getPd() {
		return pd;
	}
	public void setPd(String pd) {
		this.pd = pd;
	}
	private String zz;//设计载荷分类
	
	public String getZz() {
		return zz;
	}
	public void setZz(String zz) {
		this.zz = zz;
	}
	private String fx;//上下行方向
	
	public String getFx() {
		return fx;
	}
	public void setFx(String fx) {
		this.fx = fx;
	}
	@JTS(sql="code='610702'",spatial=Spatial.Contains,layerName="GISGEO.区县级行政区划r",message="点不在行政区划内")
	@JTS2(sql="lxdm='G5'",spatial=Spatial.Contains,layerName="GIS_LX",message="坐标不在线上")
	private IGeometry shape;

	public IGeometry getShape() {
		return shape;
	}
	public void setShape(IGeometry shape) {
		this.shape = shape;
	}
	public static void main(String[] args) {
		GisQl ql=new GisQl();
		//ql.setQldm("C285360829L0010");
		
		try {
			IPoint point = new Point();
			point.setX(115.89963971999998);
			point.setY(28.674560110000016);
			ql.setShape(point);
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		IValidator val=new DefaultValidator();
		try {
			ILog log=new HDLog();
			val.validate(ql, log);
			System.out.println(log.info());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	static {
		try 
		{
			EngineInitializer.initializeVisualBeans();
			AoInitialize ao= new AoInitialize();
			initializeArcGISLicenses(ao);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}


	private static void initializeArcGISLicenses(AoInitialize aoInit) throws AutomationException, IOException {
			if (aoInit.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngine) == esriLicenseStatus.esriLicenseAvailable)
            {
            	aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeEngine);
            } 
			else if(aoInit.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeAdvanced)==esriLicenseStatus.esriLicenseAvailable)
            {
            	aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeAdvanced);
            }	
			else if(aoInit.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeBasic)==esriLicenseStatus.esriLicenseAvailable)
            {
            	aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeBasic);
            } 	
			else if(aoInit.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB)==esriLicenseStatus.esriLicenseAvailable)
            {
            	aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeEngineGeoDB);
            }	
			else if(aoInit.isProductCodeAvailable(esriLicenseProductCode.esriLicenseProductCodeStandard)==esriLicenseStatus.esriLicenseAvailable)
            {
            	aoInit.initialize(esriLicenseProductCode.esriLicenseProductCodeStandard);
            }
			else
			{
				System.exit(-1);
			}
	}
	
}
